package com.example.xmltohtml.service;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.xml.transform.TransformerException;

/**
 * 独立的main方法示例：将XML转换为带样式的HTML
 */
public class XmlToHtmlWithStyleService {
    public static void main(String[] args) {
        try {
            // 读取XML文件内容
            String xmlPath = "src/main/resources/xml/fund_profile_example.xml";
            String xsltPath = "xslt/fund_profile.xslt"; // 带丰富样式的xslt
            String xmlContent = new String(Files.readAllBytes(Paths.get(xmlPath)), StandardCharsets.UTF_8);

            // 复用已有的XmlTransformService逻辑
            XmlTransformService service = new XmlTransformService();
            String htmlContent = service.transformXmlToHtml(xmlContent, xsltPath);

            // 输出到文件
            String outputPath = "output/fund_profile_thymeleaf.html";
            Files.createDirectories(Paths.get("output"));
            Files.write(Paths.get(outputPath), htmlContent.getBytes(StandardCharsets.UTF_8));

            System.out.println("转换成功！HTML文件已保存到: " + outputPath);
        } catch (IOException | TransformerException e) {
            System.err.println("转换失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
} 